<template>
  <div class="maincontent">
    <!-- 0 -->
    <el-form :inline="true" label-position="left" :model="form.reconnaissanceSelectionInfo" label-width="80px" ref="formData_0" :rules="formDataRules">
      <div class="maintitle">踏勘选址</div>
      <div class="formcontent">
        <el-form-item label="踏勘时间 从" label-width="100px" prop="reconnaissanceStartTime">
            <el-date-picker
              v-model="form.reconnaissanceSelectionInfo.reconnaissanceStartTime"
              type="datetime"
              placeholder="开始日期"
              value-format="yyyy-MM-dd HH:mm:ss"
              :readonly="isCurrentProcess"
            ></el-date-picker>
          </el-form-item>
          <el-form-item label="至" label-width="26px" prop="reconnaissanceEndTime">
            <el-date-picker
              v-model="form.reconnaissanceSelectionInfo.reconnaissanceEndTime"
              type="datetime"
              placeholder="结束日期"
              value-format="yyyy-MM-dd HH:mm:ss"
              :readonly="isCurrentProcess"
            ></el-date-picker>
          </el-form-item>
          <el-form-item label="踏勘人员" prop="reconnaissanceStaff">
            <el-input
              v-model="form.reconnaissanceSelectionInfo.reconnaissanceStaff"
              placeholder="请输入勘探人员"
              style="width:200px;"
              :readonly="isCurrentProcess"
            ></el-input>
          </el-form-item>
      </div>
      <div>
        <el-form-item label="踏勘选址依据" label-width="100px" prop="reconnaissanceSelectionBasis">
          <el-input
            style="width:774px;"
            :rows="3"
            type="textarea"
            v-model="form.reconnaissanceSelectionInfo.reconnaissanceSelectionBasis"
            :readonly="isCurrentProcess"
            placeholder="请填入说明"
          ></el-input>
        </el-form-item>
      </div>
      <div>
        <el-form-item label-width="420px" label="符合土地利用总体规划、农村土地整治规划、农村产业发展规划等" prop="masterPlan">
          <el-radio-group v-model="form.reconnaissanceSelectionInfo.masterPlan" :disabled="isCurrentProcess">
            <el-radio :label="1">是</el-radio>
            <el-radio :label="2">否</el-radio>
          </el-radio-group>
        </el-form-item>
      </div>
      <div>
        <el-form-item label-width="420px" label="不属于退耕还林还草区域，严禁毁林开垦" style="text-align:left;" prop="farmlandToForestry">
          <el-radio-group v-model="form.reconnaissanceSelectionInfo.farmlandToForestry" :disabled="isCurrentProcess">
            <el-radio :label="1">是</el-radio>
            <el-radio :label="2">否</el-radio>
          </el-radio-group>
        </el-form-item>
      </div>
      <div>
        <el-form-item label-width="420px" label="项目区群众有实施意愿，乡镇、村社具备项目实施的组织协调能力" prop="implementWillingness">
          <el-radio-group v-model="form.reconnaissanceSelectionInfo.implementWillingness" :disabled="isCurrentProcess">
            <el-radio :label="1">是</el-radio>
            <el-radio :label="2">否</el-radio>
          </el-radio-group>
        </el-form-item>
      </div>
      <div>
        <el-form-item label-width="420px" label="是否在25°以上不利于管护利用的陡坡开垦耕地" prop="steepSlope">
          <el-radio-group v-model="form.reconnaissanceSelectionInfo.steepSlope" :disabled="isCurrentProcess">
            <el-radio :label="1">是</el-radio>
            <el-radio :label="2">否</el-radio>
          </el-radio-group>
        </el-form-item>
      </div>
      <div>
        <el-form-item
          label-width="820px"
          label="项目实施范围红线面积原则上不超过600公顷，农用地面积比例不低于红线面积的60%，建设用地面积比例不超过红线面积的10%"
          prop="redLineArea"
        >
          <el-radio-group v-model="form.reconnaissanceSelectionInfo.redLineArea" :disabled="isCurrentProcess">
            <el-radio :label="1">是</el-radio>
            <el-radio :label="2">否</el-radio>
          </el-radio-group>
        </el-form-item>
      </div>
    </el-form>
    <!-- 1 -->
    <el-form :inline="true" label-position="left" :model="form.reconnaissanceSelectionInfo" label-width="80px" ref="formData_1" :rules="formDataRules">
      <el-form-item label-width="100px" label="踏勘选址报告" prop="reconnaissanceReportFileId">
        <el-upload :action="uploadUrl" :on-success="handleUploadSuccess" :file-list="fileList_0" :limit="1" accept=".pdf" ref="upload_01" v-if="!isCurrentProcess">
          <el-button size="small" type="primary">点击上传</el-button>
        </el-upload>
        <div class="viewDocment" v-if="isCurrentProcess">
          <!-- <span><i class="el-icon-document"/>{{form.feasibilityStudyReportFile | backFileName}}</span>
          <a style="color: rgb(64, 158, 255);margin-left:5px" @click="seePdf(form.feasibilityStudyReportFile.filePath,form.feasibilityStudyReportFile.fileName)">查看</a> -->
          <!-- <seeFujian @openPdf="seePdf" :file-name="form.feasibilityStudyReportFile | backFileName" :file-url="form.feasibilityStudyReportFile.filePath"/> -->
          <seeFujian v-if="form.reconnaissanceSelectionInfo.reconnaissanceReportFile" @openPdf="seePdf" :file-name="form.reconnaissanceSelectionInfo.reconnaissanceReportFile | backFileName" :file-url="form.reconnaissanceSelectionInfo.reconnaissanceReportFile.filePath"/>
        </div>
      </el-form-item>
    </el-form>
    <!-- 2 -->
    <el-form :inline="true" label-position="left" :model="form" label-width="80px" ref="formData_2" :rules="formDataRules">
      <div class="maintitle" style="margin-top:40px;">可研报告编制</div>
      <div class="formcontent">
        <el-form-item label="编制日期" style="margin-right:60px;" prop="preparationTime">
          <el-date-picker v-model="form.preparationTime" type="date" placeholder="编制日期" format="yyyy-MM-dd" value-format="yyyy-MM-dd HH:mm:ss" :readonly="isCurrentProcess"></el-date-picker>
        </el-form-item>
        <el-form-item label="可研究性报告模板" label-width="125px" style="margin-right:60px;" v-if="!isCurrentProcess">
          <el-button @click="handleDownloadTemp" size="small" :disabled="isCurrentProcess">下载</el-button>
        </el-form-item>        
        <el-form-item label-width="100px" label="可研究性报告" prop="feasibilityStudyReportFileId">
          <el-upload :action="uploadUrl" :on-success="handleUploadSuccess1" :limit="1" :file-list="fileList_1" accept=".pdf" ref="upload_02" v-if="!isCurrentProcess">
            <el-button size="small" type="primary">点击上传</el-button>
          </el-upload>
          <div class="viewDocment" v-if="isCurrentProcess">
            <seeFujian v-if="form.feasibilityStudyReportFile" @openPdf="seePdf" :file-name="form.feasibilityStudyReportFile | backFileName" :file-url="form.feasibilityStudyReportFile.filePath"/>
            <!-- <span><i class="el-icon-document"/>{{form.reconnaissanceSelectionInfo.reconnaissanceReportFile | backFileName}}</span>
            <a style="color: rgb(64, 158, 255);margin-left:5px" @click="seePdf(form.reconnaissanceSelectionInfo.reconnaissanceReportFile.filePath,form.reconnaissanceSelectionInfo.reconnaissanceReportFile.fileName)">查看</a> -->
          </div>
        </el-form-item>              
      </div>
    </el-form>
    <!-- 3 -->
    <el-form :inline="true" label-position="left" :model="form.projectInvestmentInfo" label-width="80px" ref="formData_3" :rules="formDataRules">
      <div class="maintitle" style="margin-top:40px;">各大工程投资情况</div>
      <div style="display: flex;-webkit-box-align: center;margin-top:20px;">
        <div class="secondtitle">工程施工费</div>
        <div style="-webkit-box-flex: 1;-webkit-flex: 1;flex: 1;">
          <el-form-item label="田间道路工程费" label-width="125px" style="margin-right:60px;" prop="roadProjectCost">
            <el-input
              @change="projectNumChange"
              type="number"
              v-model="form.projectInvestmentInfo.roadProjectCost"
              style="width:200px;"
              min="0"
              :readonly="isCurrentProcess"
            >
              <template slot="append">万元</template>
            </el-input>
          </el-form-item>
          <el-form-item label="土地平整工程费" label-width="125px" style="margin-right:60px;" prop="landLevelingProjectCost">
            <el-input
              @change="projectNumChange"
              type="number"
              v-model="form.projectInvestmentInfo.landLevelingProjectCost"
              style="width:200px;"
              min="0"              
              :readonly="isCurrentProcess"
            >
              <template slot="append">万元</template>
            </el-input>
          </el-form-item>
          <el-form-item label="农田水利工程费" label-width="125px" style="margin-right:60px;" prop="waterConservancyProjectCost">
            <el-input
              @change="projectNumChange"
              type="number"
              v-model="form.projectInvestmentInfo.waterConservancyProjectCost"
              style="width:200px;"
              min="0"
              :readonly="isCurrentProcess"
            >
              <template slot="append">万元</template>
            </el-input>
          </el-form-item>
          <el-form-item label="生态保护工程费" label-width="125px" style="margin-right:60px;" prop="ecologicalProtectionProjectCost">
            <el-input
              @change="projectNumChange"
              type="number"
              v-model="form.projectInvestmentInfo.ecologicalProtectionProjectCost"
              style="width:200px;"
              min="0"
              :readonly="isCurrentProcess"
            >
              <template slot="append">万元</template>
            </el-input>
          </el-form-item>
          <el-form-item label="其他施工费" label-width="125px" prop="otherConstructionCost">
            <el-input
              @change="projectNumChange"
              type="number"
              v-model="form.projectInvestmentInfo.otherConstructionCost"
              style="width:200px;"
              min="0"
              :readonly="isCurrentProcess"
            >
              <template slot="append">万元</template>
            </el-input>
          </el-form-item>
        </div>
      </div>
      <div style="display: flex;-webkit-box-align: center;">
        <div class="secondtitle" style="margin-right:34px;">　　其他</div>
        <div style="-webkit-box-flex: 1;-webkit-flex: 1;flex: 1;">
           <el-form-item label="其他费用" label-width="125px" style="margin-right:60px;" prop="otherCost">
            <el-input
              @change="projectNumChange"
              type="number"
              v-model="form.projectInvestmentInfo.otherCost"
              style="width:200px;"
              min="0"
              :readonly="isCurrentProcess"       
            >
              <template slot="append">万元</template>
            </el-input>
          </el-form-item>
          <el-form-item label="设备购置费" label-width="125px" style="margin-right:60px;" prop="equipmentAcquisitionCost">
            <el-input
              @change="projectNumChange"
              type="number"
              v-model="form.projectInvestmentInfo.equipmentAcquisitionCost"
              style="width:200px;"
              min="0"
              :readonly="isCurrentProcess"       
            >
              <template slot="append">万元</template>
            </el-input>
          </el-form-item>
          <el-form-item label="不可预见费用" label-width="125px" style="margin-right:60px;" prop="unforeseeableCost">
            <el-input
              @change="projectNumChange"
              type="number"
              v-model="form.projectInvestmentInfo.unforeseeableCost"
              style="width:200px;"
              min="0"
              :readonly="isCurrentProcess"
            >
              <template slot="append">万元</template>
            </el-input>
          </el-form-item>
          <el-form-item label="建设亩均投资" label-width="125px" style="margin-right:60px;" prop="constructionAverageInvestment">
            <el-input
              @change="projectNumChange"
              type="number"
              v-model="form.projectInvestmentInfo.constructionAverageInvestment"
              style="width:200px;"
              min="0"
              :readonly="isCurrentProcess"
            >
              <template slot="append">万元</template>
            </el-input>
          </el-form-item>
          <el-form-item label="新增耕地亩均投资" label-width="125px" style="margin-right:60px;" prop="cultivatedLandAverageInvestment">
            <el-input
              @change="projectNumChange"
              type="number"
              v-model="form.projectInvestmentInfo.cultivatedLandAverageInvestment"
              style="width:200px;"
              min="0"
              :readonly="isCurrentProcess"
            >
              <template slot="append">万元</template>
            </el-input>
          </el-form-item>
        </div>
      </div>
      <div style="display: flex;-webkit-box-align: center;">
        <div
          style="font-size:16px;font-family:PingFang SC;font-weight:bold;line-height:22px;color:#333333;"
        >工程施工费</div>
        <div
          style="-webkit-box-flex: 1;-webkit-flex: 1;flex: 1;margin-left:30px;font-size:16px;font-family:PingFang SC;font-weight:bold;line-height:22px;color:#4d4d4d;"
        >
          {{form.projectInvestmentInfo.constructionCost || 0}}
          <span
            style="font-size:13px;font-family:PingFang SC;font-weight:500;line-height:18px;margin-left:4px;color:#4c4c4c;"
          >万元</span>
        </div>
        <div
          style="font-size:16px;font-family:PingFang SC;font-weight:bold;line-height:22px;color:#333333;"
        >工程总投资</div>
        <div
          style="-webkit-box-flex: 1;-webkit-flex: 1;flex: 1;margin-left:30px;font-size:16px;font-family:PingFang SC;font-weight:bold;line-height:22px;color:#4d4d4d;"
        >
          {{form.projectInvestmentInfo.totalInvestment || 0}}
          <span
            style="font-size:13px;font-family:PingFang SC;font-weight:500;line-height:18px;margin-left:4px;color:#4c4c4c;"
          >万元</span>
        </div>
      </div>
      <div class="maintitle" style="margin-top:40px;">建设信息</div>
      <div class="formcontent">
        <el-form-item label="预计建设总规模" label-width="195px" style="margin-right:40px;" prop="constructionTotalScale">
          <el-input
            type="number"
            v-model="form.projectConstructionInfo.constructionTotalScale"
            style="width:200px;"
            min="0"
            :readonly="isCurrentProcess"
          >
            <template slot="append">公顷</template>
          </el-input>
        </el-form-item>
        <el-form-item label="预计整理规模" label-width="195px" style="margin-right:40px;" prop="consolidationScale">
          <el-input
            type="number"
            v-model="form.projectConstructionInfo.consolidationScale"
            style="width:200px;"
            min="0"
            :readonly="isCurrentProcess"
          >
            <template slot="append">公顷</template>
          </el-input>
        </el-form-item>
        <el-form-item label="预计开发规模" label-width="195px" style="margin-right:40px;" prop="developmentScale">
          <el-input
            type="number"
            v-model="form.projectConstructionInfo.developmentScale"
            style="width:200px;"
            min="0"
            :readonly="isCurrentProcess"
          >
            <template slot="append">公顷</template>
          </el-input>
        </el-form-item>
        <el-form-item label="预计复垦规模" label-width="195px" style="margin-right:40px;" prop="reclamationScale">
          <el-input
            type="number"
            v-model="form.projectConstructionInfo.reclamationScale"
            style="width:200px;"
            min="0"
            :readonly="isCurrentProcess"
          >
            <template slot="append">公顷</template>
          </el-input>
        </el-form-item>
        <el-form-item label="预计新增耕地总面积" label-width="195px" style="margin-right:40px;" prop="increaseCultivatedLandTotalArea">
          <el-input
            type="number"
            v-model="form.projectConstructionInfo.increaseCultivatedLandTotalArea"
            style="width:200px;"
            min="0"
            :readonly="isCurrentProcess"
          >
            <template slot="append">公顷</template>
          </el-input>
        </el-form-item>
        <el-form-item label="预计新增整理耕地面积" label-width="195px" style="margin-right:40px;" prop="increaseArableLandArea">
          <el-input
            type="number"
            v-model="form.projectConstructionInfo.increaseArableLandArea"
            style="width:200px;"
            min="0"
            :readonly="isCurrentProcess"
          >
            <template slot="append">公顷</template>
          </el-input>
        </el-form-item>
        <el-form-item label="预计新增开发耕地面积" label-width="195px" style="margin-right:40px;" prop="increaseDevelopmentCultivatedLandArea">
          <el-input
            type="number"
            v-model="form.projectConstructionInfo.increaseDevelopmentCultivatedLandArea"
            style="width:200px;"
            min="0"
            :readonly="isCurrentProcess"
          >
            <template slot="append">公顷</template>
          </el-input>
        </el-form-item>
        <el-form-item label="预计新增复垦耕地面积" label-width="195px" style="margin-right:40px;" prop="increaseReclamationCultivatedLandArea">
          <el-input
            type="number"
            v-model="form.projectConstructionInfo.increaseReclamationCultivatedLandArea"
            style="width:200px;"
            min="0"
            :readonly="isCurrentProcess"
          >
            <template slot="append">公顷</template>
          </el-input>
        </el-form-item>
        <el-form-item label="预计基本农田整理规模" label-width="195px" style="margin-right:40px;" prop="basicFarmlandConsolidationScale">
          <el-input
            type="number"
            v-model="form.projectConstructionInfo.basicFarmlandConsolidationScale"
            style="width:200px;"
            min="0"
            :readonly="isCurrentProcess"
          >
            <template slot="append">公顷</template>
          </el-input>
        </el-form-item>
        <el-form-item label="预计可用与占补平衡面积" label-width="195px" style="margin-right:40px;" prop="balancedArea">
          <el-input
            type="number"
            v-model="form.projectConstructionInfo.balancedArea"
            style="width:200px;"
            min="0"
            :readonly="isCurrentProcess"
          >
            <template slot="append">公顷</template>
          </el-input>
        </el-form-item>
        <el-form-item label="预计建成高标准基本农田规模" label-width="195px" style="margin-right:40px;" prop="highStandardBasicFarmlandArea">
          <el-input
            type="number"
            v-model="form.projectConstructionInfo.highStandardBasicFarmlandArea"
            style="width:200px;"
            min="0"
            :readonly="isCurrentProcess"
          >
            <template slot="append">公顷</template>
          </el-input>
        </el-form-item>
        <el-form-item label="灾毁耕地面积" label-width="195px" style="margin-right:40px;" prop="damagedCultivatedLandArea">
          <el-input
            type="number"
            v-model="form.projectConstructionInfo.damagedCultivatedLandArea"
            style="width:200px;"
            min="0"
            :readonly="isCurrentProcess"
          >
            <template slot="append">公顷</template>
          </el-input>
        </el-form-item>
      </div>
    </el-form>
    <!-- 4 -->
    <el-form :inline="true" label-position="left" :model="form" label-width="80px" ref="formData_4" :rules="formDataRules">
      <div class="maintitle" style="line-height:40px;">
        主要建设内容        
        <el-form-item v-if="!isCurrentProcess" style="margin-right:24px;margin-left:30px;">
          <el-button @click="handleDownloadTemp1" size="small" :disabled="isCurrentProcess">模板下载</el-button>
        </el-form-item>
        <el-form-item prop="mainConstructionContent">          
          <el-upload
            :headers="{authorization: token}"
            :action="uploadUrl1"
            :on-success="handleUpload"
            :limit="1"
            accept=".xlsx"
            :disabled="isCurrentProcess"
            ref="upload_03"
            v-if="!isCurrentProcess"
          >
            <el-button size="small" type="primary">工程量导入</el-button>
          </el-upload>
        </el-form-item>          
      </div>
    </el-form>
    <div>
      <el-table :data="form.mainConstructionContent" style="width: 100%">
        <el-table-column prop="sequence" label="序号" width="180"></el-table-column>
        <el-table-column prop="projectType" label="工程类型" width="180"></el-table-column>
        <el-table-column prop="projectName" label="工程名称"></el-table-column>
        <el-table-column prop="specs" label="规格" width="180"></el-table-column>
        <el-table-column prop="nums" label="数量" width="180"></el-table-column>
        <el-table-column prop="remark" label="备注"></el-table-column>
      </el-table>
    </div>
    <div style="margin:50px 0;">
      <el-button type="primary" v-show="!isCurrentProcess" @click="onSubmit">提交</el-button>
      <el-button @click="$router.push('/projectManagement/planningStage/dealwith')">返回</el-button>
    </div>
    <el-dialog
      :close-on-click-modal="false"
      :title="pdfName"
      :visible.sync="pdfFlag"
      width="50%">
      <div class="pdfBox">
        <iframe :src="$https + pdfUrl" style="width:100%;height:600px;" frameborder="0"></iframe>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import config from "@/config/index.js";
import seeFujian from "@/components/seeFujian";
import { getToken } from "@/utils/auth";
import {
  upTo,
  getProjectInfoById
} from "@/api/feasibilityStudy/fillInDistrictCounty.js";
import {
  queryProjectProcess
} from "@/api/feasibilityStudy/common.js"
import {
  validateNotNull,
  validateUpload,
  validateDatetime,
  validateNotNullArray
} from "@/utils/validate.js"
import moment from "moment";
import axios from 'axios';
export default {
  components:{
    seeFujian
  },
  data() {
    return {
      isLook:false,
      pdfUrl:'',
      pdfFlag:false,
      pdfName:'',
      projectId: localStorage.getItem('projectId') * 1,
      form: {
        projectId: localStorage.getItem('projectId') * 1,
        feasibilityStudyReportFileId: "",
        preparationTime: moment(new Date()).format('YYYY-MM-DD HH:mm:ss'),
        reconnaissanceSelectionInfo: {
          reconnaissanceReportFileId: "",
          reconnaissanceStartTime: "",
          reconnaissanceSelectionBasis: "",
          reconnaissanceEndTime: "",
          reconnaissanceStaff: "",
          masterPlan: 1,
          farmlandToForestry: 1,
          implementWillingness: 1,
          steepSlope: 1,
          projectId: localStorage.getItem('projectId') * 1,
          redLineArea: 1
        },
        projectInvestmentInfo: {
          roadProjectCost: 0,
          landLevelingProjectCost: 0,
          waterConservancyProjectCost: 0,
          ecologicalProtectionProjectCost: 0,
          otherConstructionCost: 0,
          equipmentAcquisitionCost: 0,
          unforeseeableCost: 0,
          constructionAverageInvestment: 0,
          projectId: localStorage.getItem('projectId') * 1,
          cultivatedLandAverageInvestment: 0,
          totalInvestment: 0,
          otherCost:0
        },
        projectConstructionInfo: {
          constructionTotalScale: 0,
          consolidationScale: 0,
          developmentScale: 0,
          reclamationScale: 0,
          increaseCultivatedLandTotalArea: 0,
          increaseArableLandArea: 0,
          increaseDevelopmentCultivatedLandArea: 0,
          increaseReclamationCultivatedLandArea: 0,
          basicFarmlandConsolidationScale: 0,
          balancedArea: 0,
          highStandardBasicFarmlandArea: 0,
          projectId: localStorage.getItem('projectId') * 1,
          damagedCultivatedLandArea: 0
        },
        mainConstructionContent: null
      },
      fileList_0:[],
      fileList_1:[],
      //表单验证
      formDataRules:{
        reconnaissanceStartTime:[{validator:validateDatetime,trigger:"change"}],
        reconnaissanceEndTime:[{validator:validateDatetime,trigger:"change"}],
        reconnaissanceStaff:[{validator:validateNotNull,trigger:"blur"}],
        reconnaissanceSelectionBasis:[{validator:validateNotNull,trigger:"blur"}],
        masterPlan:[{validator:validateNotNull,trigger:"change"}],
        farmlandToForestry:[{validator:validateNotNull,trigger:"change"}],
        implementWillingness:[{validator:validateNotNull,trigger:"change"}],
        steepSlope:[{validator:validateNotNull,trigger:"change"}],
        redLineArea:[{validator:validateNotNull,trigger:"change"}],
        feasibilityStudyReportFileId:[{validator:validateUpload,trigger:"change"}],
        reconnaissanceReportFileId:[{validator:validateUpload,trigger:"change"}],
        mainConstructionContent:[{validator:validateNotNullArray,trigger:"change"}],
      },
      uploadUrl: config.uploadUrl,
      baseUrl:config.baseUrl,
      uploadUrl1:config.baseUrl + "/renovation/feasibilityStudy/uploadMainConstructionContent",
      tableData: [],
      token: getToken(),
      pickerOptions:{
        disabledDate(time) {
            return time.getTime() < Date.now();
          },
      }
    };
  },
  computed:{
    isCurrentProcess:function () {
      let isTrue = localStorage.getItem('key') == 'FEASIBILITY_STUDY_DIST_REPORT';
      if(localStorage.getItem("lookStatus") == 2){
        isTrue = false
      }
      return !isTrue
    }
  },
  filters:{
    backFileName:function (data) {
      if(data){
        return data.fileName
      }else{
        return ""
      }
    },
    backFilePath:function (data,baseUrl) {
      if(data){
        return baseUrl + data.filePath
      }else{
        return "#"
      }
    }
  },
  created() {
    this.getData();
  },
  methods: {
    moment,
    onSubmit() {
      let isTrue0 = true,isTrue1=true,isTrue2=true,isTrue3=true,isTrue4=true;
      this.$refs['formData_0'].validate(valid => {
        isTrue0 = valid
      })    
      this.$refs['formData_1'].validate(valid => {
        isTrue1 = valid
      })
      this.$refs['formData_2'].validate(valid => {
        isTrue2 = valid
      })
      this.$refs['formData_3'].validate(valid => {
        isTrue3 = valid
      })
      this.$refs['formData_4'].validate(valid => {
        isTrue4 = valid
      })
      if(isTrue0&&isTrue1&&isTrue2&&isTrue3&&isTrue4){
        //提交
        const loading = this.$loading({
          lock: true,
          text: "Loading",
          spinner: "el-icon-loading",
          background: "rgba(0, 0, 0, 0.7)"
        });
        for (const a in this.form.projectInvestmentInfo) {
          this.form.projectInvestmentInfo[a] =
            this.form.projectInvestmentInfo[a] * 1;
        }
        for (const a in this.form.projectConstructionInfo) {
          this.form.projectConstructionInfo[a] =
            this.form.projectConstructionInfo[a] * 1;
        };
        upTo(this.form)
          .then(res => {
            loading.close();
            this.$message({
              message: "提交成功！",
              type: "success"
            });
            this.$router.push('/projectManagement/planningStage/dealwith');
          })
          .catch(res => {
            loading.close();
          });
      }      
    },
    //查看当前PDF
    seePdf(url,name){
      console.log(url)
      this.pdfUrl = url
      this.pdfName = name
      this.pdfFlag = true
      
    },
    getreport(response, file, fileList) {
      this.fileList = [];
      this.fileList.push(file);
    },
    handleUploadSuccess: function(res, file, fileList) {
      //踏勘选址报告文件上传成功回调
      this.form.reconnaissanceSelectionInfo.reconnaissanceReportFileId = res.data.id;
      this.$refs['formData_1'].validate();
    },
    handleUploadSuccess1: function(res, file, fileList) {
      //可研究性报告文件上传成功回调
      this.form.feasibilityStudyReportFileId = res.data.id;
      this.$refs['formData_2'].validate();
    },
    handleDownloadTemp: function() {
      //下载可研究性报告模板
      const url = config.baseUrl + "/renovation/templatefile/可研究性报告模板.pdf";
      axios.get(url,{responseType:'blob'}).then(res => {
        const url = window.URL.createObjectURL(new Blob([res.data]));
        const link = document.createElement('a');
        let fname = '可研究性报告模板.pdf';
        link.href = url;
        link.setAttribute('download', fname);
        link.click();
      })
    },
    handleDownloadTemp1: function() {
      //下载主要建设内容工程量模板
      let a = document.createElement("a");
      a.href = config.baseUrl + "/renovation/templatefile/主要建设内容.xlsx";
      a.click();
    },
    projectNumChange() {
      //计算工程总投资
      this.form.projectInvestmentInfo.totalInvestment = Number(
        this.form.projectInvestmentInfo.roadProjectCost * 1 +
          this.form.projectInvestmentInfo.landLevelingProjectCost * 1 +
          this.form.projectInvestmentInfo.waterConservancyProjectCost * 1 +
          this.form.projectInvestmentInfo.ecologicalProtectionProjectCost *
            1 +
          this.form.projectInvestmentInfo.otherConstructionCost * 1 +
          this.form.projectInvestmentInfo.equipmentAcquisitionCost * 1 +
          this.form.projectInvestmentInfo.unforeseeableCost * 1 + 
          this.form.projectInvestmentInfo.otherCost * 1
      );
      this.form.projectInvestmentInfo.constructionCost = Number(
        this.form.projectInvestmentInfo.roadProjectCost * 1 +
          this.form.projectInvestmentInfo.landLevelingProjectCost * 1 +
          this.form.projectInvestmentInfo.waterConservancyProjectCost * 1 +
          this.form.projectInvestmentInfo.ecologicalProtectionProjectCost *
            1 +
          this.form.projectInvestmentInfo.otherConstructionCost * 1
      )
    },
    handleUpload(res, file, fileList) {
      //工程量导入
      this.form.mainConstructionContent = res.data;
      this.$refs['formData_4'].validate();
    },
    getData() {
      //获取回显信息
      const loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });
      getProjectInfoById({ projectId: this.projectId })
        .then(res => {
          let form = res.data;
          if(!form.projectId){
            form.projectId = localStorage.getItem('projectId') * 1
          };
          if(form.feasibilityStudyReportFile){
            form.feasibilityStudyReportFileId = form.feasibilityStudyReportFile.id;
            this.fileList_1 = [{name:form.feasibilityStudyReportFile.fileName}];
          }else{
            form.feasibilityStudyReportFileId = "";
          };
          if(form.reconnaissanceSelectionInfo && form.reconnaissanceSelectionInfo.reconnaissanceReportFile){
            form.reconnaissanceSelectionInfo.reconnaissanceReportFileId = form.reconnaissanceSelectionInfo.reconnaissanceReportFile.id;
            this.fileList_0 = [{name:form.reconnaissanceSelectionInfo.reconnaissanceReportFile.fileName}];         
          }
          if(!form.reconnaissanceSelectionInfo){
            form.reconnaissanceSelectionInfo = {
              reconnaissanceReportFileId: "",
              reconnaissanceStartTime: "",
              reconnaissanceSelectionBasis: "",
              reconnaissanceEndTime: "",
              projectId: this.projectId,
              reconnaissanceStaff: "",
              masterPlan: 1,
              farmlandToForestry: 1,
              implementWillingness: 1,
              steepSlope: 1,
              redLineArea: 1
            }
          }else{
            form.reconnaissanceSelectionInfo.projectId = this.projectId
          }
          if(!form.projectInvestmentInfo){
            form.projectInvestmentInfo = {
              roadProjectCost: 0,
              landLevelingProjectCost: 0,
              waterConservancyProjectCost: 0,
              projectId: this.projectId,
              ecologicalProtectionProjectCost: 0,
              otherConstructionCost: 0,
              equipmentAcquisitionCost: 0,
              unforeseeableCost: 0,
              constructionAverageInvestment: 0,
              cultivatedLandAverageInvestment: 0,
              totalInvestment: 0,
              otherCost:0
            }
          }
          if(!form.projectConstructionInfo){
            form.projectConstructionInfo = {
              constructionTotalScale: 0,
              consolidationScale: 0,
              developmentScale: 0,
              reclamationScale: 0,
              projectId: this.projectId,
              increaseCultivatedLandTotalArea: 0,
              increaseArableLandArea: 0,
              increaseDevelopmentCultivatedLandArea: 0,
              increaseReclamationCultivatedLandArea: 0,
              basicFarmlandConsolidationScale: 0,
              balancedArea: 0,
              highStandardBasicFarmlandArea: 0,
              damagedCultivatedLandArea: 0
            }
          };
          if(!form.preparationTime){
            form.preparationTime = moment(new Date()).format('YYYY-MM-DD HH:mm:ss');
          }
          this.form = form;
          loading.close();
        })
        .catch(res => {
          loading.close();
        });
    }
  }
};
</script>

<style lang="scss" scoped>
  .maincontent {
    padding: 10px 35px;
    .maintitle {
      font-size: 18px;
      font-family: PingFang SC;
      font-weight: bold;
      line-height: 25px;
      color: #4d4d4d;
    }
    .formcontent {
      margin-top: 30px;
    }
    .secondtitle {
      font-size: 14px;
      font-family: PingFang SC;
      font-weight: 500;
      line-height: 20px;
      margin-right: 20px;
      line-height: 38px;
    }
  }
</style>
 